//
//  MTDiscoverTool.swift
//  MT
//
//  Created by ooops on 2020/5/18.
//  Copyright © 2020 张强. All rights reserved.
//

import Foundation
import RxSwift
import RxDataSources
import Moya
import Result
import MTCategory

public class MTCreateTaskTool: NSObject {
    public override init() {
        super.init()
    }
}

extension MTCreateTaskTool {
    
    /// 查询聚会任务类型信息
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func querySubject(provider: MTProvider<MTCreateTaskAPI>,
                               complete: @escaping (MTPartyTaskModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.partySubject).subscribe(onNext: { (result:Result<MTPartyTaskModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 发布聚会任务接口
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func createParty(provider: MTProvider<MTCreateTaskAPI>,
                               parameters: [String : Any],
                               complete: @escaping (BaseComponentModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.addTask(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    /// 编辑聚会任务信息
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func editParty(provider: MTProvider<MTCreateTaskAPI>,
                               parameters: [String : Any],
                               complete: @escaping (MTPartyListModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.editTask(parameters)).subscribe(onNext: { (result:Result<MTPartyListModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 查询机会任务列表
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func queryPartyList(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (MTPartyListModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.joinOrMineTask(parameters)).subscribe(onNext: { (result:Result<MTPartyListModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 查询聚会任务详情
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func queryPartyDetail(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (MTPartyListModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.taskDetail(parameters)).subscribe(onNext: { (result:Result<MTPartyListModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 加入聚会任务申请
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func joinPartyTask(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (BaseComponentModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.joinTask(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 查询聚会任务申请信息
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func queryNotify(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (MTTaskInviteInfoModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.queryNotiy(parameters)).subscribe(onNext: { (result:Result<MTTaskInviteInfoModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 操作聚会任务
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: 操作类型,0申请1拒绝2同意,3删除成员 - type
    ///   - complete: complete description
    ///   - failure: failure description
    class func operateInvite(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (BaseComponentModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.operateInvite(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 发布者取消聚会任务
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func cancelPartyTask(provider: MTProvider<MTCreateTaskAPI>,
                              parameters: [String : Any],
                               complete: @escaping (BaseComponentModel?) -> Swift.Void,
                               failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.cancelPartyTask(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 查询聚会任务群角色相关信息
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func partyTaskGroupInfo(provider: MTProvider<MTCreateTaskAPI>,
                                  parameters: [String : Any],
                                  complete: @escaping (MTTaskStatusInfoModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.queryPartyClubStatus(parameters)).subscribe(onNext: { (result:Result<MTTaskStatusInfoModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 聚会任务签到
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description    
    class func partySign(provider: MTProvider<MTCreateTaskAPI>,
                                  parameters: [String : Any],
                                  complete: @escaping (BaseComponentModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.partySign(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 发放聚会任务金
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func sendPartyTaskGift(provider: MTProvider<MTCreateTaskAPI>,
                                  parameters: [String : Any],
                                  complete: @escaping (BaseComponentModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.sendPartyTaskGift(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 结束俱乐部聚会任务
    /// - Parameters:
    ///   - provider: provider description
    ///   - parameters: parameters description
    ///   - complete: complete description
    ///   - failure: failure description
    class func endParty(provider: MTProvider<MTCreateTaskAPI>,
                                  parameters: [String : Any],
                                  complete: @escaping (BaseComponentModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.endParty(parameters)).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 服务器时间戳
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func timastamp(provider: MTProvider<MTCreateTaskAPI>,
                                  complete: @escaping (BaseComponentModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.timestamp).subscribe(onNext: { (result:Result<BaseComponentModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 弃用 - 查询报名人数最多的聚会任务
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func queryTopTask(provider: MTProvider<MTCreateTaskAPI>,
                                  complete: @escaping (MTPartyListModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.timestamp).subscribe(onNext: { (result:Result<MTPartyListModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    
    /// 查询聚会任务申请消息未读条数
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func queryNofityCount(provider: MTProvider<MTCreateTaskAPI>,
                                  complete: @escaping (MTNotifyCountModel?) -> Swift.Void,
                                  failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.queryNotifyCount).subscribe(onNext: { (result:Result<MTNotifyCountModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
}
